package com.foreknow.controller;

import com.foreknow.po.DeliveryAddress;
import com.foreknow.service.DeliveryAddressService;
import com.foreknow.service.Impl.DeliveryAddressServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class DeliveryAddressController {

    public Object listDeliveryAddressByUserId(HttpServletRequest request){
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        String userId = request.getParameter("userId");
        List<DeliveryAddress> list = service.listDeliveryAddressByUserId(userId);
        return list;
    }

    public Object getDeliveryAddressById(HttpServletRequest request){
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        int daId = Integer.parseInt(request.getParameter("daId"));
        DeliveryAddress deliveryAddress = service.getDeliveryAddressById(daId);
        return deliveryAddress;
    }

    public Object saveDeliveryAddress(HttpServletRequest request){
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        String contactName = request.getParameter("contactName");
        int contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address = request.getParameter("address");
        String userId = request.getParameter("userId");
        int result = service.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
        return result;
    }

    public Object updateDeliveryAddress(HttpServletRequest request){
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        int daId = Integer.parseInt(request.getParameter("daId"));
        String contactName = request.getParameter("contactName");
        int contactSex = Integer.parseInt(request.getParameter("contactSex"));
        String contactTel = request.getParameter("contactTel");
        String address =request.getParameter("address");
        int result = service.updateDeliveryAddress(daId,contactName,contactSex,contactTel,address);
        return result;
    }

    public Object removeDeliveryAddress(HttpServletRequest request){
        DeliveryAddressService service = new DeliveryAddressServiceImpl();
        int daId = Integer.parseInt(request.getParameter("daId"));
        int result = service.removeDeliveryAddress(daId);
        return result;
    }


}
